package com.example.workassignback.Mapper;

import com.example.workassignback.POJO.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Select("Select * from Users where cardId = #{cardId} and password = #{password};")
    User loginCheck(String cardId, String password);

    @Select("SELECT\n" +
            "    CASE\n" +
            "        WHEN EXISTS (SELECT * FROM Patients WHERE uId = #{id}) THEN 'Patient'\n" +
            "        WHEN EXISTS (SELECT * FROM Doctors where uId=#{id}) THEN 'Doctor'\n" +
            "        END AS Source\n" +
            "LIMIT 1;")
    String selectRoleByUId(Integer id);

    @Select("select * from Users where cardId=#{cardId}")
    User selectUserByCardId(String cardId);

    @Insert("insert into Users (cardId,password,phone,name,gender,birthday) value(#{cardId},#{password},#{phone},#{name},#{gender},#{birthday}) ")
    @Options(useGeneratedKeys = true, keyProperty = "uId")
    Integer insertUser(User user);

    @Insert("insert into Doctors (uId) value (#{uId}); ")
    Integer insertDoctor(Integer uId);

    @Insert("insert into Patients (uId) value (#{uId}); ")
    Integer insertPatient(Integer uId);
}